package lcr;

public class Test0021 {
}

class Solution0021_1 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode ans = new ListNode();
        ans.next=head;
        ListNode l=ans,r=ans;

        for (int i = 0; i < n; i++) {
            r=r.next;
        }

        while (r.next!=null){
            l=l.next;
            r=r.next;
        }

        l.next=l.next.next;

        return ans.next;
    }
}
